package com.quanshu.change.person.view;

import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.quanshu.change.person.entity.SeckillGoodsBuyDetailEntity;
import com.quanshu.exchange.R;
import com.quanshu.exchange.support.api.ShopInterface;
import com.quanshu.exchange.support.net.BaseResponse;
import com.quanshu.exchange.support.net.core.BaseObserver;
import com.quanshu.exchange.support.net.core.BaseTransformer;
import com.quanshu.exchange.support.net.core.NetClient;
import com.quanshu.exchange.support.utils.LogUtil;
import com.quanshu.exchange.support.utils.RxViewHelper;
import com.quanshu.exchange.ui.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SeckillGoodsBuyDetialActivity extends BaseActivity {
    @BindView(R.id.back)
    LinearLayout back;
    @BindView(R.id.title)
    RelativeLayout title;
    @BindView(R.id.txt1)
    TextView txt1;
    @BindView(R.id.txt11)
    TextView txt11;
    @BindView(R.id.cl1)
    ConstraintLayout cl1;
    @BindView(R.id.txt2)
    TextView txt2;
    @BindView(R.id.txt21)
    TextView txt21;
    @BindView(R.id.cl2)
    ConstraintLayout cl2;
    @BindView(R.id.txt3)
    TextView txt3;
    @BindView(R.id.txt31)
    TextView txt31;
    @BindView(R.id.txt32)
    TextView txt32;
    @BindView(R.id.cl3)
    ConstraintLayout cl3;
    @BindView(R.id.txt4)
    TextView txt4;
    @BindView(R.id.txt41)
    TextView txt41;
    @BindView(R.id.cl4)
    ConstraintLayout cl4;
    @BindView(R.id.txt5)
    TextView txt5;
    @BindView(R.id.txt51)
    TextView txt51;
    @BindView(R.id.cl5)
    ConstraintLayout cl5;
    @BindView(R.id.txt6)
    TextView txt6;
    @BindView(R.id.txt61)
    TextView txt61;
    @BindView(R.id.cl6)
    ConstraintLayout cl6;
    @BindView(R.id.txt7)
    TextView txt7;
    @BindView(R.id.txt71)
    TextView txt71;
    @BindView(R.id.cl7)
    ConstraintLayout cl7;
    @BindView(R.id.txt8)
    TextView txt8;
    @BindView(R.id.txt81)
    TextView txt81;
    @BindView(R.id.cl8)
    ConstraintLayout cl8;
    @BindView(R.id.txt9)
    TextView txt9;
    @BindView(R.id.txt91)
    TextView txt91;
    @BindView(R.id.cl9)
    ConstraintLayout cl9;
    @BindView(R.id.txt10)
    TextView txt10;
    @BindView(R.id.txt211)
    TextView txt211;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_seckill_goods_buy_detial);
        ButterKnife.bind(this);
        getData();
    }

    //获取秒杀商品购买详情
    private void getData() {
        RxViewHelper.getInstance().clicks(back, aVoid -> {
            finish();
        });
        String goodsId = getIntent().getExtras().getString(HotGoodsActivity.GOODS_ID);
        if (!TextUtils.isEmpty(goodsId)) {
            if (currentUser != null) {
                NetClient.getInstance().getShopService(ShopInterface.class)
                        .getHotGoodsDetail(currentUser.getMemberid(), "1", goodsId)
                        .compose(new BaseTransformer<>(this, true, false))
                        .subscribe(new BaseObserver<BaseResponse<SeckillGoodsBuyDetailEntity>>() {
                            @Override
                            public void onSuccess(BaseResponse<SeckillGoodsBuyDetailEntity> response) {
                                if (response.getCode() == 1) {
                                    txt11.setText(response.getData().getGoods_name());
                                    txt21.setText("¥ " + response.getData().getGoods_price());
                                    txt211.setText(response.getData().getGoods_price());
                                    txt31.setText("¥ " + response.getData().getReal_price() + " +");//下单现金
                                    txt10.setText(response.getData().getReal_price() + " + ");
                                    if (response.getData().getPayment_options() == 0) {
                                        txt31.setVisibility(View.VISIBLE);
                                        txt21.setVisibility(View.VISIBLE);
                                        txt211.setVisibility(View.INVISIBLE);
                                        txt10.setVisibility(View.INVISIBLE);
                                    } else if (response.getData().getPayment_options() == 3) {
                                        txt31.setVisibility(View.INVISIBLE);
                                        txt21.setVisibility(View.INVISIBLE);
                                        txt211.setVisibility(View.VISIBLE);
                                        txt10.setVisibility(View.VISIBLE);
                                    }
                                    txt32.setText(response.getData().getTickets());
                                    txt41.setText(response.getData().getPay_time());
                                    txt51.setText(response.getData().getGoods_nums());
                                    txt61.setText(response.getData().getPick_nums());
                                    txt71.setText(response.getData().getNumber());
                                    txt81.setText(response.getData().getSale_number());
                                    txt91.setText(response.getData().getFail_number());
                                }
                            }

                            @Override
                            public void onFailure(Throwable e) {
                                LogUtil.printException(e);
                            }
                        });
            }
        }

    }
}
